@extends("layout.app")

@section("content")
    <div class="form-inline">

        <div class="form-group has-success">
            <input class="form-control" id="begin_time" placeholder="开始时间"/>
        </div>
        <div class="form-group has-success">
            <input class="form-control" id="end_time" placeholder="结束时间"/>
        </div>
        <div class="form-group has-success">
            &nbsp;<button id="button" class="btn btn-default" onclick="jQuery('#rowed3').setGridParam({postData: postData()}).trigger('reloadGrid')"><i class="fa fa-search"></i> 查询</button>
        </div>
        <div class="form-group has-success">
            &nbsp;<button id="button" class="btn btn-success" onclick="setDate('<?php echo date("Y-m-d", strtotime("Monday this week"))?>', '')"> 本周申请</button>
        </div>
        <div class="form-group has-success">
            &nbsp;<button id="button" class="btn btn-info" onclick="setDate('<?php echo date("Y-m-d", strtotime("Monday this week")-604800)?>', '<?php echo date("Y-m-d", strtotime("last Sunday"))?>')"> 上周申请</button>
        </div>
        <div class="form-group has-success">
            &nbsp;<button id="button" class="btn btn-warning" onclick="setDate('<?php echo date("Y-m-01")?>', '')"> 本月申请</button>
        </div>
        <div class="form-group has-success">
            &nbsp;<button id="button" class="btn btn-danger" onclick="setDate('<?php echo date("Y-m-01",  strtotime(date("Y-m-01") . " -1 month"))?>', '<?php echo date("Y-m-d",  strtotime(date("Y-m-01") . " -1 day"))?>')"> 上月申请</button>
        </div>
    </div>
    <div class="separator"></div>
    <div class="box-body">

        <table id="rowed3"></table>
        <div id="prowed3"></div>

    </div>
<script>

$(document).ready(function() {

	var data = {
        url :"/tikuan/chao/log",
        postData: postData(),
        colNames: ["id", "时间", "超总ID", "名称", "账号","银行卡号", "提现金额", "状态"],
        colModel: [
            {
                name  : "id",
                key   : true,
                hidden: true
            }, {
                name: "create_time",
                formatter:'date',
                formatoptions: {srcformat: 'Y-m-d H:i:s', newformat: 'Y-m-d H:i:s'},
                searchoptions: {
                sopt: ['lt', 'le', 'gt', 'ge'],
                	dataInit : function (elem) {
                    	$(elem).datepicker({
                            dateFormat: 'yy-mm-dd',
                            monthNames: ['一月','二月','三月','四月','五月','六月','七月','八月','九月','十月','十一月','十二月'],
                            dayNamesMin: ['日','一','二','三','四','五','六'] });
                	}
                }
            }, {
                name: "user_id"
            }, {
                name: "user_name",
                sortable: false
            }, {
                name    : "email",
                sortable: false,
                search  : false
            }, {
                name: "card_number",
                sortable: false
            },{
                name: "rmb"
            },{
                name: "status",
                sortable: false,
                stype: 'select',
                searchoptions: {
                    sopt: ["eq", "ne"],
                    value: "0:审核中;2:通过;3:拒绝"
                },
                formatter: function(cellvalue, options, object) {

                    cellvalue = cellvalue.toString();
                    switch (cellvalue) {
                        case "0":
                       	 return '<a href="javascript:;" onclick="rmb('+object.id+","+object.user_id+')" data-toggle="modal" data-target="#fhModal"><span class="text text-info">审核中</span></a>';
                        case "2":
                            return '<span class="text text-success">通过</span>';
                    }
                    return '<span class="text text-danger">拒绝</span>';
                }
            }],
        caption: '<i class="fa fa-list"></i> {{$label2}}',
        sortname: "id",
        sortorder: "desc",
        editurl: "/tikuan/chao/edit",
        autowidth: false,
        gridComplete: function() {
            var sum = 0;
            if (($(this).getCol("sum").length)){
                sum = $(this).getCol("sum")[0];
            }
            $(this).footerData("set", {
                "shenqing": "总计: <i class=\"fa fa-jpy\"></i> " + sum
            });
        }
    };

	jqGrid(data);

    $(".form-inline .form-control").datepicker({
        dateFormat: 'yy-mm-dd',
        monthNames: ['一月','二月','三月','四月','五月','六月','七月','八月','九月','十月','十一月','十二月'],
        dayNamesMin: ['日','一','二','三','四','五','六'] });
});

function excel(){
	var begin = $("#begin_time").val();
    var end = $("#end_time").val();
	window.location.href="/tikuan/chao/table?begin_time="+begin+"&"+"end_time="+end;
}

function setDate(begin_time, end_time) {

    $("#begin_time").val(begin_time);
    $("#end_time").val(end_time);

    jQuery('#rowed3').setGridParam({postData: postData()}).trigger('reloadGrid')
}

function postData() {

    return {
        begin_time: $("#begin_time").val(),
        end_time: $("#end_time").val()
    }
}

function rmb(id, user_id,rmb) {
	$("#rmbModalLabel").html("选择[用户Id: <span class='text-danger'>" + user_id + "</span>]的审核结果");
	$("input[name=id]").val(id);
}


<?php if($request->session()->get("message")):?>
alert("<?php echo $request->session()->get("message")?>");
<?php endif?>

</script>
<div class="modal fade" id="fhModal" tabindex="-1" role="dialog" aria-labelledby="fhModalLabel">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
			<div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-name="Close"><span aria-hidden="true">×</span></button>
                <h4 class="modal-title" id="rmbModalLabel"></h4>
            </div>
            <div class="modal-body">
            	<form id="rmb-form1" method="post" action="/tikuan/edit">
            		{!! csrf_field() !!}
                	<input type="hidden" name="id" />
                	<input type="hidden" name="user_type" value="1"/>
                	<input type="hidden" name="status" value="2" />
            	</form>
            	<form id="rmb-form2" method="post" action="/tikuan/edit">
            		{!! csrf_field() !!}
                	<input type="hidden" name="id" />
                	<input type="hidden" name="user_type" value="1"/>
                	<input type="hidden" name="status" value="3" />
            	</form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-success" onclick="$('#rmb-form1').submit()"> 通过</button>
                <button type="button" class="btn btn-danger" onclick="$('#rmb-form2').submit()"> 拒绝</button>
                <button id="fh-cancel" type="button" class="btn btn-default" data-dismiss="modal">取消</button>
            </div>
        </div>
    </div>
</div>
@endsection